import { lazy, Suspense } from "react";
import { Navigate } from "react-router-dom";
import type { ReactNode } from "react";

const Home = lazy(() => import("@/views/home/index.tsx"));
const Dashboard = lazy(() => import("@/views/dashboard/index.tsx"));
const GPU = lazy(() => import("@/views/AccInfo/gpu/index.tsx"));
const CPU = lazy(() => import("@/views/AccInfo/cpu/index.tsx"));
const Center = lazy(() => import("@/views/AccInfo/center/index.tsx"));
const Memory = lazy(() => import("@/views/AccInfo/memory/index.tsx"));
const SSD = lazy(() => import("@/views/AccInfo/ssd/index.tsx"));
const HDD = lazy(() => import("@/views/AccInfo/hdd/index.tsx"));
const Login = lazy(() => import("@/views/login/index.tsx"));
const NotFound = lazy(() => import("@/views/error/index.tsx"));

const Video = lazy(() => import("@/views/video/index.tsx"));

const Chat = lazy(() => import("@/views/other/chat/index.tsx"));
const Resource = lazy(() => import("@/views/other/resource/index.tsx"));

const VideoDetail = lazy(() => import("@/views/video/detail.tsx"));




//闪屏优化
const lazyLoad = (children: ReactNode): ReactNode => {
  return <Suspense fallback={<>Loading...</>}>{children}</Suspense>;
};

export interface RouteConfig {
  path: string;
  element: React.ReactNode;
  auth: boolean;
  children?: RouteConfig[];
  redirect?: string;
}

export const routers: RouteConfig[] = [
  {
    path: "/login",
    element: lazyLoad(<Login />),
    auth: false,
  },
  
  
  {
    path: "/",
    element: lazyLoad(<Home />),
    auth: true,
    children: [
      {
        path: "/dashboard",
        element: lazyLoad(<Dashboard />),
        auth: true,
      },
      {
        path: "/accinfo",
        element: lazyLoad(<Navigate to="/accinfo/gpu" />),
        auth: true,
      },
      {
        path: "/accinfo/gpu",
        element: lazyLoad(<GPU />),
        auth: true,
      },
      {
        path: "/accinfo/cpu",
        element: lazyLoad(<CPU />),
        auth: true,
      },
      {
        path: "/accinfo/center",
        element: lazyLoad(<Center />),
        auth: true,
      },
      {
        path: "/accinfo/memory",
        element: lazyLoad(<Memory />),
        auth: true,
      },
      {
        path: "/accinfo/ssd",
        element: lazyLoad(<SSD />),
        auth: true,
      },
      {
        path: "/accinfo/hdd",
        element: lazyLoad(<HDD />),
        auth: true,
      },
      {
        path: "/video",
        element: lazyLoad(<Video />),
        auth: true,
      },
      {
        path: "/other",
        element: lazyLoad(<Navigate to="/other/chat" />),
        auth: true,
      },
      {
        path: "/other/chat",
        element: lazyLoad(<Chat />),
        auth: true,
      },
      {
        path: "/other/resource",
        element: lazyLoad(<Resource />),
        auth: true,
      },
    ],
  },

  {
    path: "/404",
    element: lazyLoad(<NotFound />),
    auth: true,
  },
  {
    path: "*",
    element: lazyLoad(<Navigate to="/404" />),
    auth: true,
  },
  {
    path: "/video/detail/:id",
    element: lazyLoad(<VideoDetail />),
    auth: true,
  },
];
